package com.avengers.modules.spider.whois.querier;

import com.avengers.core.kit.StringKit;
import com.avengers.modules.auction.bean.enums.Suffix;
import com.avengers.modules.spider.whois.bean.WhoisInfo;

/**
 * @author wy
 * @since 2019/07/29 下午3:38
 */
public enum WhoisProp implements WhoisAnalysis {
    // cn
    cn(Suffix.cn.value, Cn.ANALYSIS),
    com(Suffix.com.value, ComNet.ANALYSIS),
    net(Suffix.net.value, ComNet.ANALYSIS),
    cc(Suffix.cc.value, Cc.ANALYSIS),
    tv(Suffix.tv.value, Tv.ANALYSIS),
    chinese(Suffix.cnZh.value, CnChinese.ANALYSIS),
    org(Suffix.org.value, Org.ANALYSIS);

    public final String suffix;
    private final WhoisAnalysis whoisAnalysis;

    WhoisProp(String suffix, WhoisAnalysis whoisAnalysis) {
        this.suffix = suffix;
        this.whoisAnalysis = whoisAnalysis;
    }

    public static WhoisProp of(String domain) {
        if (StringKit.isBlank(domain)) {
            return null;
        }
        for (WhoisProp value : values()) {
            if (domain.endsWith(value.suffix)) {
                return value;
            }
        }
        return null;
    }

    @Override
    public String server() {
        return this.whoisAnalysis.server();
    }

    @Override
    public String notFoundRemark() {
        return this.whoisAnalysis.notFoundRemark();
    }

    @Override
    public String unRegisteredOnLineRemark() {
        return this.whoisAnalysis.unRegisteredOnLineRemark();
    }

    @Override
    public void transferLine(WhoisInfo whoisInfo, String line) {
        whoisAnalysis.transferLine(whoisInfo, line);
    }
}
